<template>
    <div class="page_chanye">
        <common-header :title="'产业信息编辑'">
            <span slot="overwrite-left"></span>
        </common-header>
        <div class="btn-save" @click="saveLandTransferInfo">保存</div>
        <div class="pages-main" style="height: calc( 100vh - 45px)">
            <div class="item-info">
                <div class="item-item">
                    <div class="item-item every-block-padding item-inline">
                        <span class="item-itemLabel">是否有果园</span>
                        <select class="translateBlock" v-model="info.hasGarden"
                                style="text-align-last: right;;width: 6.7rem;font-size:0.38rem;">
                            <option :value="1">是</option>
                            <option :value="0">否</option>
                        </select>
                    </div>
                </div>
                <div v-if="info.hasGarden === 1">
                    <div class="item-item">
                        <x-input title="面积(亩)" type="number" v-model="info.gardenArea"
                                 placeholder="请输入面积(亩)">
                        </x-input>
                    </div>
                    <div class="item-item">
                        <x-input title="种植作物" v-model="info.crop"
                                 placeholder="请输入种植作物">
                        </x-input>
                    </div>
                    <div class="item-item">
                        <x-input title="年产值" type="number" v-model="info.gardenGDP"
                                 placeholder="请输入年产值">
                        </x-input>
                    </div>
                </div>
                <div class="item-item">
                    <div class="item-item every-block-padding item-inline">
                        <span class="item-itemLabel">是否经营户</span>
                        <select class="translateBlock" v-model="info.hadBusiness"
                                style="text-align-last: right;;width: 6.7rem;font-size:0.38rem;">
                            <option :value="1">是</option>
                            <option :value="0">否</option>
                        </select>
                    </div>
                </div>
                <div v-if="info.hadBusiness === 1">
                    <div class="item-item">
                        <div class="item-item every-block-padding item-inline">
                            <span class="item-itemLabel">经营项目</span>
                            <select class="translateBlock" v-model="info.businesscontent"
                                    style="text-align-last: right;;width: 7rem;font-size:0.38rem;"
                                    placeholder="请选择经营项目">
                                <option :value="'农家乐'">农家乐</option>
                                <option :value="'餐饮'">餐饮</option>
                                <option :value="'其他'">其他</option>
                            </select>
                        </div>
                    </div>

                    <div class="item-item">
                        <x-input title="床位数量" type="number" v-model="info.bednumber"
                                 placeholder="请输入床位数量">
                        </x-input>
                    </div>
                    <div class="item-item">
                        <x-input title="年产值" type="number" v-model="info.businessGDP"
                                 placeholder="请输入年产值">
                        </x-input>
                    </div>
                </div>

            </div>
        </div>
    </div>
</template>

<script>
    import resident from '../../services/resident'
    import {XInput, Selector, Datetime} from 'vux'
    import {checkNumber,checkIntNumber} from '../../utils/validate'

    export default {
        name: "chanye",
        components: {
            XInput, Selector, Datetime
        },
        data() {
            return {
                info: {
                    familyId: this.$route.query.familyid,
                    villagecode: this.$route.query.villagecode,
                    hasGarden: Number(this.$route.query.hasGarden),
                    gardenArea: this.$route.query.gardenarea,
                    crop: this.$route.query.crop,
                    gardenGDP: this.$route.query.gardengdp,
                    hadBusiness:Number(this.$route.query.hadbusiness),
                    businesscontent: this.$route.query.businesscontent,
                    bednumber: this.$route.query.bednumber,
                    businessGDP:Number(this.$route.query.businessgdp),
                },
            }
        },

        created() {

        },
        watch: {},
        methods: {
            // 保存土地信息
            saveLandTransferInfo() {

                if (this.info.hasGarden === 1) {
                    let param = {
                        gardenArea: '请输入正确的面积（数字类型且最多保留两位小数）',
                        crop: '请输入种植作物',
                        gardenGDP: '请输入正确的年产值（数字类型且最多保留两位小数）',
                    }
                    for (let i in param) {
                        if (!this.info[i]) {
                            this.$vux.toast.show({
                                text: param[i],
                                type: 'text',
                                position: 'middle',
                            })
                            return;
                        }
                    }

                    if(!checkNumber(this.info.gardenArea,'面积')){
                        return
                    }
                    if(!checkNumber(this.info.gardenGDP,'年产值')){
                        return
                    }

                }

                if (this.info.hadBusiness === 1) {
                    let param = {
                        businesscontent: '请选择经营项目',
                        bednumber: '请输入床位数量',
                        businessGDP: '请输入年产值',
                    }
                    for (let i in param) {
                        if (!this.info[i]) {
                            this.$vux.toast.show({
                                text: param[i],
                                type: 'text',
                                position: 'middle',
                            })
                            return;
                        }
                    }
                    if(!checkIntNumber(this.info.bednumber,'床位数量')){
                        return
                    }
                    if(!checkNumber(this.info.businessGDP,'年产值')){
                        return
                    }
                }

                this.info.expropriationtime = this.info.expropriationtime ?  this.info.expropriationtime + ' ' +
                '00:00:00' : '';
                let _param = this.$tools.invokeUAF('resident/updateFamilyGardenInfo', this.info)
                resident.updateFamilyGardenInfo(_param).then(res => {
                    this.info.expropriationtime = this.info.expropriationtime.slice(0, 10)
                })
            },
        },
    };
</script>

<style lang="less" rel="stylesheet/less" type="text/css">
    .page_chanye {
    }

</style>
